package edu.isistan.matching.adapters;

import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;

import edu.isistan.metamodel.DataType;


public class DateTimeAdapter extends PrimitiveTypeAdapter {

	private static Set<String> fullyCompatible = new HashSet<String>();
	
	private static Set<String> loosyCompatible = new HashSet<String>();
	
	static Hashtable<String, String> codigosHash = new Hashtable<String, String>();
	
	static {
		fullyCompatible.add("dateTime");
		
		loosyCompatible.add("string");
		loosyCompatible.add("long");
		//TODOPor ahora conversiones a java.util.Date
		codigosHash.put("java.lang.Long", "new java.util.Date(" + CODE_MASK + ")");
		codigosHash.put("long", "new java.util.Date(" + CODE_MASK + ")");
		
		codigosHash.put("java.lang.String", "new java.util.Date(" + CODE_MASK + ")");
		codigosHash.put("string", "new java.util.Date(" + CODE_MASK + ")");
	}
	
	@Override
	public Set<String> getFullyCompatibles() {
		return fullyCompatible;
	}

	@Override
	public Set<String> getLoosyCompatibles() {
		return loosyCompatible;
	}

	@Override
	public Object toValue(DataType element) {
		PrimitiveTypeAdapter adapter = AdapterFactory.getAdapter(element);
		return adapter.valueof(getValue());
	}

	@Override
	public Object valueof(Object value) {
		return new Date(Date.parse(value.toString()));
	}
	
	@Override
	public Hashtable<String, String> getLibraryCode() {
		return codigosHash;
	}

}
